﻿using System;
using Mono.Cecil.Cil;
using Mono.Cecil.PE;
using Mono.Collections.Generic;

namespace Mono.Cecil
{
	// Token: 0x0200001E RID: 30
	internal sealed class ImmediateModuleReader : ModuleReader
	{
		// Token: 0x06000145 RID: 325 RVA: 0x00002E44 File Offset: 0x00001044
		public ImmediateModuleReader(Image image) : base(image, ReadingMode.Immediate)
		{
		}

		// Token: 0x06000146 RID: 326 RVA: 0x00002E50 File Offset: 0x00001050
		protected override void ReadModule()
		{
			this.module.Read<ModuleDefinition>(this.module, delegate(ModuleDefinition module, MetadataReader reader)
			{
				base.ReadModuleManifest(reader);
				this.ReadModule(module, true);
			});
		}

		// Token: 0x06000147 RID: 327 RVA: 0x0000DB28 File Offset: 0x0000BD28
		public void ReadModule(ModuleDefinition module, bool resolve_attributes)
		{
			this.resolve_attributes = resolve_attributes;
			bool hasAssemblyReferences = module.HasAssemblyReferences;
			if (hasAssemblyReferences)
			{
				Mixin.Read(module.AssemblyReferences);
			}
			bool hasResources = module.HasResources;
			if (hasResources)
			{
				Mixin.Read(module.Resources);
			}
			bool hasModuleReferences = module.HasModuleReferences;
			if (hasModuleReferences)
			{
				Mixin.Read(module.ModuleReferences);
			}
			bool hasTypes = module.HasTypes;
			if (hasTypes)
			{
				this.ReadTypes(module.Types);
			}
			bool hasExportedTypes = module.HasExportedTypes;
			if (hasExportedTypes)
			{
				Mixin.Read(module.ExportedTypes);
			}
			this.ReadCustomAttributes(module);
			AssemblyDefinition assembly = module.Assembly;
			bool flag = module.kind == ModuleKind.NetModule || assembly == null;
			if (!flag)
			{
				this.ReadCustomAttributes(assembly);
				this.ReadSecurityDeclarations(assembly);
			}
		}

		// Token: 0x06000148 RID: 328 RVA: 0x0000DBE8 File Offset: 0x0000BDE8
		private void ReadTypes(Collection<TypeDefinition> types)
		{
			for (int i = 0; i < types.Count; i++)
			{
				this.ReadType(types[i]);
			}
		}

		// Token: 0x06000149 RID: 329 RVA: 0x0000DC1C File Offset: 0x0000BE1C
		private void ReadType(TypeDefinition type)
		{
			this.ReadGenericParameters(type);
			bool hasInterfaces = type.HasInterfaces;
			if (hasInterfaces)
			{
				this.ReadInterfaces(type);
			}
			bool hasNestedTypes = type.HasNestedTypes;
			if (hasNestedTypes)
			{
				this.ReadTypes(type.NestedTypes);
			}
			bool hasLayoutInfo = type.HasLayoutInfo;
			if (hasLayoutInfo)
			{
				Mixin.Read(type.ClassSize);
			}
			bool hasFields = type.HasFields;
			if (hasFields)
			{
				this.ReadFields(type);
			}
			bool hasMethods = type.HasMethods;
			if (hasMethods)
			{
				this.ReadMethods(type);
			}
			bool hasProperties = type.HasProperties;
			if (hasProperties)
			{
				this.ReadProperties(type);
			}
			bool hasEvents = type.HasEvents;
			if (hasEvents)
			{
				this.ReadEvents(type);
			}
			this.ReadSecurityDeclarations(type);
			this.ReadCustomAttributes(type);
		}

		// Token: 0x0600014A RID: 330 RVA: 0x0000DCD4 File Offset: 0x0000BED4
		private void ReadInterfaces(TypeDefinition type)
		{
			Collection<InterfaceImplementation> interfaces = type.Interfaces;
			for (int i = 0; i < interfaces.Count; i++)
			{
				this.ReadCustomAttributes(interfaces[i]);
			}
		}

		// Token: 0x0600014B RID: 331 RVA: 0x0000DD0C File Offset: 0x0000BF0C
		private void ReadGenericParameters(IGenericParameterProvider provider)
		{
			bool flag = !provider.HasGenericParameters;
			if (!flag)
			{
				Collection<GenericParameter> genericParameters = provider.GenericParameters;
				for (int i = 0; i < genericParameters.Count; i++)
				{
					GenericParameter genericParameter = genericParameters[i];
					bool hasConstraints = genericParameter.HasConstraints;
					if (hasConstraints)
					{
						this.ReadGenericParameterConstraints(genericParameter);
					}
					this.ReadCustomAttributes(genericParameter);
				}
			}
		}

		// Token: 0x0600014C RID: 332 RVA: 0x0000DD70 File Offset: 0x0000BF70
		private void ReadGenericParameterConstraints(GenericParameter parameter)
		{
			Collection<GenericParameterConstraint> constraints = parameter.Constraints;
			for (int i = 0; i < constraints.Count; i++)
			{
				this.ReadCustomAttributes(constraints[i]);
			}
		}

		// Token: 0x0600014D RID: 333 RVA: 0x0000DDA8 File Offset: 0x0000BFA8
		private void ReadSecurityDeclarations(ISecurityDeclarationProvider provider)
		{
			bool flag = !provider.HasSecurityDeclarations;
			if (!flag)
			{
				Collection<SecurityDeclaration> securityDeclarations = provider.SecurityDeclarations;
				bool flag2 = !this.resolve_attributes;
				if (!flag2)
				{
					for (int i = 0; i < securityDeclarations.Count; i++)
					{
						SecurityDeclaration securityDeclaration = securityDeclarations[i];
						Mixin.Read(securityDeclaration.SecurityAttributes);
					}
				}
			}
		}

		// Token: 0x0600014E RID: 334 RVA: 0x0000DE0C File Offset: 0x0000C00C
		private void ReadCustomAttributes(ICustomAttributeProvider provider)
		{
			bool flag = !provider.HasCustomAttributes;
			if (!flag)
			{
				Collection<CustomAttribute> customAttributes = provider.CustomAttributes;
				bool flag2 = !this.resolve_attributes;
				if (!flag2)
				{
					for (int i = 0; i < customAttributes.Count; i++)
					{
						CustomAttribute customAttribute = customAttributes[i];
						Mixin.Read(customAttribute.ConstructorArguments);
					}
				}
			}
		}

		// Token: 0x0600014F RID: 335 RVA: 0x0000DE70 File Offset: 0x0000C070
		private void ReadFields(TypeDefinition type)
		{
			Collection<FieldDefinition> fields = type.Fields;
			for (int i = 0; i < fields.Count; i++)
			{
				FieldDefinition fieldDefinition = fields[i];
				bool hasConstant = fieldDefinition.HasConstant;
				if (hasConstant)
				{
					Mixin.Read(fieldDefinition.Constant);
				}
				bool hasLayoutInfo = fieldDefinition.HasLayoutInfo;
				if (hasLayoutInfo)
				{
					Mixin.Read(fieldDefinition.Offset);
				}
				bool flag = fieldDefinition.RVA > 0;
				if (flag)
				{
					Mixin.Read(fieldDefinition.InitialValue);
				}
				bool hasMarshalInfo = fieldDefinition.HasMarshalInfo;
				if (hasMarshalInfo)
				{
					Mixin.Read(fieldDefinition.MarshalInfo);
				}
				this.ReadCustomAttributes(fieldDefinition);
			}
		}

		// Token: 0x06000150 RID: 336 RVA: 0x0000DF18 File Offset: 0x0000C118
		private void ReadMethods(TypeDefinition type)
		{
			Collection<MethodDefinition> methods = type.Methods;
			for (int i = 0; i < methods.Count; i++)
			{
				MethodDefinition methodDefinition = methods[i];
				this.ReadGenericParameters(methodDefinition);
				bool hasParameters = methodDefinition.HasParameters;
				if (hasParameters)
				{
					this.ReadParameters(methodDefinition);
				}
				bool hasOverrides = methodDefinition.HasOverrides;
				if (hasOverrides)
				{
					Mixin.Read(methodDefinition.Overrides);
				}
				bool isPInvokeImpl = methodDefinition.IsPInvokeImpl;
				if (isPInvokeImpl)
				{
					Mixin.Read(methodDefinition.PInvokeInfo);
				}
				this.ReadSecurityDeclarations(methodDefinition);
				this.ReadCustomAttributes(methodDefinition);
				MethodReturnType methodReturnType = methodDefinition.MethodReturnType;
				bool hasConstant = methodReturnType.HasConstant;
				if (hasConstant)
				{
					Mixin.Read(methodReturnType.Constant);
				}
				bool hasMarshalInfo = methodReturnType.HasMarshalInfo;
				if (hasMarshalInfo)
				{
					Mixin.Read(methodReturnType.MarshalInfo);
				}
				this.ReadCustomAttributes(methodReturnType);
			}
		}

		// Token: 0x06000151 RID: 337 RVA: 0x0000DFF0 File Offset: 0x0000C1F0
		private void ReadParameters(MethodDefinition method)
		{
			Collection<ParameterDefinition> parameters = method.Parameters;
			for (int i = 0; i < parameters.Count; i++)
			{
				ParameterDefinition parameterDefinition = parameters[i];
				bool hasConstant = parameterDefinition.HasConstant;
				if (hasConstant)
				{
					Mixin.Read(parameterDefinition.Constant);
				}
				bool hasMarshalInfo = parameterDefinition.HasMarshalInfo;
				if (hasMarshalInfo)
				{
					Mixin.Read(parameterDefinition.MarshalInfo);
				}
				this.ReadCustomAttributes(parameterDefinition);
			}
		}

		// Token: 0x06000152 RID: 338 RVA: 0x0000E05C File Offset: 0x0000C25C
		private void ReadProperties(TypeDefinition type)
		{
			Collection<PropertyDefinition> properties = type.Properties;
			for (int i = 0; i < properties.Count; i++)
			{
				PropertyDefinition propertyDefinition = properties[i];
				Mixin.Read(propertyDefinition.GetMethod);
				bool hasConstant = propertyDefinition.HasConstant;
				if (hasConstant)
				{
					Mixin.Read(propertyDefinition.Constant);
				}
				this.ReadCustomAttributes(propertyDefinition);
			}
		}

		// Token: 0x06000153 RID: 339 RVA: 0x0000E0BC File Offset: 0x0000C2BC
		private void ReadEvents(TypeDefinition type)
		{
			Collection<EventDefinition> events = type.Events;
			for (int i = 0; i < events.Count; i++)
			{
				EventDefinition eventDefinition = events[i];
				Mixin.Read(eventDefinition.AddMethod);
				this.ReadCustomAttributes(eventDefinition);
			}
		}

		// Token: 0x06000154 RID: 340 RVA: 0x0000E104 File Offset: 0x0000C304
		public override void ReadSymbols(ModuleDefinition module)
		{
			bool flag = module.symbol_reader == null;
			if (!flag)
			{
				this.ReadTypesSymbols(module.Types, module.symbol_reader);
			}
		}

		// Token: 0x06000155 RID: 341 RVA: 0x0000E134 File Offset: 0x0000C334
		private void ReadTypesSymbols(Collection<TypeDefinition> types, ISymbolReader symbol_reader)
		{
			for (int i = 0; i < types.Count; i++)
			{
				TypeDefinition typeDefinition = types[i];
				bool hasNestedTypes = typeDefinition.HasNestedTypes;
				if (hasNestedTypes)
				{
					this.ReadTypesSymbols(typeDefinition.NestedTypes, symbol_reader);
				}
				bool hasMethods = typeDefinition.HasMethods;
				if (hasMethods)
				{
					this.ReadMethodsSymbols(typeDefinition, symbol_reader);
				}
			}
		}

		// Token: 0x06000156 RID: 342 RVA: 0x0000E190 File Offset: 0x0000C390
		private void ReadMethodsSymbols(TypeDefinition type, ISymbolReader symbol_reader)
		{
			Collection<MethodDefinition> methods = type.Methods;
			for (int i = 0; i < methods.Count; i++)
			{
				MethodDefinition methodDefinition = methods[i];
				bool flag = methodDefinition.HasBody && methodDefinition.token.RID != 0U && methodDefinition.debug_info == null;
				if (flag)
				{
					methodDefinition.debug_info = symbol_reader.Read(methodDefinition);
				}
			}
		}

		// Token: 0x04000083 RID: 131
		private bool resolve_attributes;
	}
}
